package com.itheima.search.controller;

import com.itheima.search.domain.HotNewsVO;
import com.itheima.search.domain.NewsVO;
import com.itheima.search.domain.SearchParam;
import com.itheima.search.domain.SearchResult;
import com.itheima.search.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    @Qualifier("searchServiceImpl")
    private ISearchService searchService;

    /**
     * 搜索新闻
     */
    @PostMapping
    public SearchResult search(@RequestBody SearchParam param) throws IOException {
        return searchService.searchNews(param);
    }

    /**
     * 根据新闻ID查询新闻
     */
    @GetMapping("/{newsId}")
    public NewsVO search(@PathVariable Long newsId) throws IOException {
        //根据新闻ID查询新闻
        return searchService.searchNewsById(newsId);
    }

    /**
     * 获取热搜新闻
     */
    @GetMapping("/hot-news")
    public List<HotNewsVO> getHotNews() {
        return searchService.getHotNews();
    }
}